
local aocai = fk.CreateSkill {
  name = "lvshi__aocai",
}

Fk:loadTranslationTable{
  ["lvshi__aocai"] = "傲才",
  [":lvshi__aocai"] = "当你需要使用一张基本牌时，若你没有智策略，你可以获得智策略并视为使用之；回合开始时，你可令一名己方角色交给你两张牌，然后你失去智策略。",
  ["#lvshi__aocai-choose"] = "傲才：你可令一名己方角色交给你两张牌，然后你失去智策略",
  ["#lvshi__aocai-chosecard"] = "傲才：请选择交给%src的两张牌",

  ["$lvshi__aocai1"] = "英才卓越，功盖一国，非我诸葛恪莫属。",
  ["$lvshi__aocai2"] = "壮士当唱大风歌，宵小之徒能几何？",
}

local ls = require "packages/lvshi/utility"

aocai:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local names = player:getViewAsCardNames(aocai.name, all_names, nil, {})
    if #names == 0 then return end
    return UI.CardNameBox {choices = names, all_choices = all_names}
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if #cards ~= 0 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = aocai.name
    return card
  end,
  enabled_at_play = function(self, player)
    return ls.getStrategy(player, false) == "courage" or ls.getStrategy(player, false) == "none"
  end,
  enabled_at_response = function(self, player, response)
    return not response and (ls.getStrategy(player, false) == "courage" or ls.getStrategy(player, false) == "none")
  end,
  before_use = function(self, player, use)
    ls.gainStrategy(player, "scheme")
  end,
})


aocai:addEffect(fk.TurnStart, {
  priority = 0.9,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(aocai.name) and target == player
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = table.filter(room:getOtherPlayers(player), function (p)
        return ls.isFriend(player, p) and #p:getCardIds("he") >= 2 end),
      max_num = 1,
      min_num = 1,
      skill_name = aocai.name,
      cancelable = true,
      prompt = "#lvshi__aocai-choose",
    })
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self)
    if to then
      local cards = room:askToCards(to, {
        max_num = 2,
        min_num = 2,
        skill_name = aocai.name,
        cancelable = false,
        include_equip = true,
        prompt = "#lvshi__aocai-chosecard:"..player.id,
      })
      if #cards == 2 then
        room:obtainCard(player, cards, false, fk.ReasonGive, player, aocai.name)
      end
      ls.loseStrategy(player, "scheme")
    end
  end,
})

return aocai